/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
		package menu;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import dao.StudentDao;
import model.Student;
public class Find_Menu {
	Student find_student;
	JFrame find_menu;
	JPanel p1,p2;
	JLabel l1;
	JTextField text;
	JTextArea show;
	JButton find_find,find_cancel;
	public void student_find(){
		find_menu = new JFrame("学生信息查找");
		p1 = new JPanel();
		p2 = new JPanel();
		l1 = new JLabel("学号：");
		text = new JTextField(16);
		show = new JTextArea(100,100);
		find_find = new JButton("搜索");
		find_cancel = new JButton("取消");
		find_cancel.addActionListener(new Monitor2());
		find_find.addActionListener(new Monitor2());
		find_menu.add(p1,BorderLayout.NORTH);
		find_menu.add(show,BorderLayout.CENTER);
		find_menu.add(p2,BorderLayout.SOUTH);
		p1.add(l1);
		p1.add(text);
		p2.add(find_find);
		p2.add(find_cancel);
		find_menu.setBounds(400,200,400,400);
		find_menu.setVisible(true);
	}
	
	private class Monitor2 implements ActionListener{
    	public void actionPerformed(ActionEvent e) {
			if(e.getActionCommand().equals("取消")){
				find_menu.setVisible(false); 
				new Son_menu().studentmenu();
				}
			if(e.getActionCommand().equals("搜索")){
				find_student = new StudentDao().findOne(Integer.parseInt(text.getText()));
				if(find_student.getName()!= null)
					{
					String str = "  姓名："+find_student.getName()+"\n  学号："+find_student.getId()+"\n  性别："+find_student.getSex()+"\n  生日："+find_student.getBorn_date()+"\n  院系代号："+find_student.getDepart_id()+"\n  班级："+find_student.getClass_name()+" ";
					show.setText("");
					show.insert(str, 1);
					}
				else{
					show.setText("");
					show.insert("学生信息未找到", 1);}
				}
				if(e.getActionCommand().equals("删除")){
					new StudentDao().deleteInfo(find_student);
					show.setText("");
					show.insert("学生信息已删除", 1);
					}
    	}
	}
	
	public static void main(String args[]){
		new Find_Menu().student_find();
	}
	
}


